<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>
        <div>
            <table id="table1">
                <tr>
                    <th>
                        id:
                    </th>
                    <th>
                        姓名：
                    </th>
                    <th>
                        性别：
                    </th>
                    <th>
                        班级：
                    </th>
                    <th>
                        创建时间：
                    </th>
                    <th>
                        更新时间
                    </th>
                </tr>
            </table>
        </div>
    </div>
    <script src="./jquery-3.6.0.min.js"></script>
    <script src="./baseurl.js"></script>
    <script src="./js.js"></script>
    <script>
        $(function () {
            let table1 = $('#table1');
            let rowData = $('.rowData');
            rowData.remove();
            let id = getUrlParam('id');
            let pid = parseInt(id);
            getlistclass(pid).then(res => {
                let obj = res.data;
                console.log(obj);

                let h = `
                <tr class="rowData" key="${obj.id}">
                <td>${obj.id}</td>
                <td>${obj.CName}</td>
                <td>${obj.Sex}</td>
                <td>${obj.ClassName}</td>
                <td>${obj.lid}</td>
                <td>
                <input type="button" value="编辑" onclick="update(${obj.id})">
                <input type="button" value="注销" onclick="del(${obj.id})">
                </td>
                </tr>
                   `
                table1.append(h);
            })
        })
        function update(id) {
            location.href = './createclass.html?id=' + id;
        }
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
        function del(id) {
            delclass(id).then(data => {
                if (data.code === 1000) {
                    $(`[key=${id}]`).remove();
                }
                else {
                    alert('删除失败')
                }
            })
        }
    </script>
</body>

</html>